﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <#include "../common/header.ftl"/>
    <script>
        $(function () {
            //绑定删除按钮
            /*$('.btn-delete').click(function () {
                var url = $(this).data('url');
                //弹出确认框
                $.messager.confirm("温馨提示","亲,确定删除吗?",function () {
                    $.get(url,function (data) {
                        handleResult(data);
                    })
                },);
            });*/


            $('.btn-input').click(function () {
                var json = $(this).data('json');
                //填充之前先清空 转成DOM
                $("#editForm")[0].reset();
                if(json) /*有数据才显示*/
                {
                    $('input[name="id"]').val(json.id);
                    $('input[name="name"]').val(json.name);
                    $('input[name="sn"]').val(json.sn);
                }


                $('#editModal').modal('show');
            });
            $('.btn-submit').click(function () {
                //改用ajax提交
                $('#editForm').ajaxSubmit(function (data) {
                    handleResult(data);
                });
            });

        })

        /*function handleResult(data) {
            if(data.success)
            {
                $.messager.alert("温馨提示","亲,执行成功");
                setTimeout(function () {
                    window.location.reload();
                },2000);
            }else{
                $.messager.alert("温馨提示",data.errorMsg);
            }
        }*/
        
    </script>
</head>
<body>

<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">部门编辑</h4>
            </div>
            <div class="modal-body">
                    <form class="form-horizontal" action="/department/saveOrUpdate.do" method="post" id="editForm">
                        <input type="hidden" name="id">
                        <div class="form-group" >
                            <label class="col-sm-3 control-label">部门名称：</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" name="name"
                                       placeholder="请输入部门的名称">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">部门编号：</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" name="sn"
                                       placeholder="请输入部门编号">
                            </div>
                        </div>
                    </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-submit">提交</button>
            </div>
        </div>
    </div>
</div>


<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu="department"/>
                <#assign menu="department">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">部门管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <a href="javascript:;" class="btn btn-success btn-input">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>部门名称</th>
                    <th>部门编号</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.name}</td>
                       <td>${entity.sn}</td>
                       <td>
                           <a class="btn btn-info btn-xs btn-input" href="javascript:;" data-json='${entity.json}'>
                               <span class="glyphicon glyphicon-pencil "></span> 编辑
                           </a>
                           <@shiro.hasPermission name="department:delete">
                           <a href="javascript:;" class="btn btn-danger btn-xs btn-delete" data-url="/department/delete.do?id=${entity.id}">
                               <span class="glyphicon glyphicon-trash"></span> 删除
                           </a>
                           </@shiro.hasPermission>
                       </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>






</body>
</html>